﻿using System.Web.Script.Serialization;

namespace SBACN.WebSite.Common
{
	/// <summary>
	/// 对象序列化
	/// </summary>
	public class Serializer
	{
		/// <summary>
		/// 将可序列化的对象转换为Json字符串
		/// </summary>
		/// <param name="obj">可序列化的对象</param>
		/// <returns>Json字符串</returns>
		public static string JsonSerializer(object obj)
		{
			JavaScriptSerializer js = new JavaScriptSerializer();
			return js.Serialize(obj);
		}
		/// <summary>
		/// 将Json字符串转换为指定类型的对象
		/// </summary>
		/// <typeparam name="T">指定对象的类型</typeparam>
		/// <param name="jsonString">Json字符串</param>
		/// <returns>指定类型的对象</returns>
		public static T JsonSerializer<T>(string jsonString)
		{
			JavaScriptSerializer js = new JavaScriptSerializer();
			return js.Deserialize<T>(jsonString);
		}
	}
}